<template>
  <div class="cwdt">
    <el-row :gutter="20">
      <el-col :sm="24" :lg="24" style="margin-top: 20px">
        <el-card v-loading="loading" element-loading-text="Loading..." element-loading-background="#178af01a">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true" class="queryForm" label-width="80px">
            <el-form-item label="标题" prop="title">
              <el-input v-model="queryParams.title" placeholder="请输入标题" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="事项类型" prop="sxlx">
              <!-- <el-select
                v-model="queryParams.sxlx"
                class="formSelct"
                popper-class="countyprop"
                clearable
                placeholder="请选择事项类型"
                style="width: 120px"
              >
                <el-option v-for="item in sxlxList" :key="item.label" :label="item.label" :value="item.value" />
              </el-select> -->
              <el-input v-model="queryParams.sxlx" placeholder="请输入年度" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="年度" prop="nf">
              <el-input v-model="queryParams.nf" placeholder="请输入年度" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button sfzh="primary" icon="Search" @click="handleQuery">查询</el-button>
            </el-form-item>
          </el-form>
          <div v-for="el in tableData" :key="el.title" class="tableItem" @click="handleDetail(el)">
            <div class="left">
              <img style="width: 100%; height: 100%" :src="getUrl(el.tp)" alt="" />
            </div>
            <div class="right">
              <div class="top">
                <div class="top-title">
                  <div class="title">{{ el.title }}</div>
                  <div class="sxlx">{{ el.sxlx }}</div>
                </div>
                <div class="content">{{ el.sxsm }}</div>
              </div>
              <div class="time">{{ el.fbsj }}</div>
            </div>
          </div>
          <el-empty v-if="tableData.length == 0" description="暂无数据" />
          <el-pagination
            v-if="tableData.length > 0"
            v-model:current-page="queryParams.pageNum"
            v-model:page-size="queryParams.pageSize"
            :total="queryParams.total"
            background
            class="pagination"
            layout="prev, pager, next"
            @current-change="handleCurrentChange"
          />
        </el-card>
      </el-col>
    </el-row>
    <el-dialog v-model="dialog.visible" class="customDialog" :title="dialog.title" width="500px">
      <el-form ref="demoFormRef" class="queryForm" :model="form" label-width="100px">
        <!-- readonly="readonly" -->
        <el-form-item label="事项标题" prop="title">
          <el-input v-model="form.title" />
        </el-form-item>
        <el-form-item label="发布时间" prop="fbsj">
          <el-input v-model="form.fbsj" />
        </el-form-item>
        <el-form-item label="发布人" prop="fbr">
          <el-input v-model="form.fbr" />
        </el-form-item>
        <el-form-item label="年度" prop="year">
          <el-input v-model="form.year" />
        </el-form-item>
        <el-form-item label="文化内容" prop="sxsm">
          <el-input v-model="form.sxsm" type="textarea" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" />
        </el-form-item>
        <el-form-item label="图片" prop="ssxz">
          <imageUpload v-model="form.tp" :isShowTip="false" :disabled="true" />
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import useMapStore from '@/store/modules/map';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const $szxcapi = (proxy as any)?.$szxcapi;
const loading = ref(false);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  title: '',
  sxlx: '',
  nf: '',
  total: 0
});
const demoFormRef = ref<ElFormInstance>();
const initFormData = {
  id: undefined,
  title: undefined,
  fbsj: undefined,
  sxsm: undefined,
  sxlx: undefined,
  fbr: undefined,
  tp: undefined,
  year: undefined,
  remark: undefined
};
const data = reactive({
  form: { ...initFormData }
});
const { form } = toRefs(data);
const dialog = reactive<DialogOption>({
  visible: false,
  title: '详情信息'
});
const reset = () => {
  form.value = { ...initFormData };
  demoFormRef.value?.resetFields();
};
const sxlxList = ref([
  {
    label: '重要会议',
    value: '重要会议'
  }
]);
const tableData = ref([
  // {
  //   tp: 'wuyu1',
  //   title: '2024年上班年役前教育人员名单公示',
  //   sxsm: '经区征兵领导小组研究，确定我镇黄金龙等7名青年参加上半年役前教育训练，现将参训人员相关信息予以公示，接受广大群众监督、举报。',
  //   fbsj: '2024-02-08',
  //   sxlx: '重要会议'
  // },
  // {
  //   tp: 'wuyu1',
  //   title: '2024年上班年役前教育人员名单公示',
  //   sxsm: '经区征兵领导小组研究，确定我镇黄金龙等7名青年参加上半年役前教育训练，现将参训人员相关信息予以公示，接受广大群众监督、举报。',
  //   fbsj: '2024-02-08',
  //   sxlx: '重大活动'
  // }
]);
const handleQuery = () => {
  // 查询
  init(true);
};
const handleCurrentChange = (e) => {
  queryParams.value.pageNum = e;
  init(false);
};
const getUrl = (icon) => {
  return new URL(icon, import.meta.url).href;
};
const init = async (flag) => {
  loading.value = true;
  if (flag) {
    queryParams.value.pageNum = 1;
  }
  const params = {
    'ssc': useMapStore().szxcCountryText,
    ...queryParams.value
  };
  const data = await $szxcapi.cwdtQuery(params);
  tableData.value = data.rows;
  queryParams.value.total = data.total;
  loading.value = false;
};
const handleDetail = async (el) => {
  reset();
  const _id = el?.id;
  const res = await $szxcapi.cwdtInfoQuery({ id: _id });
  Object.assign(form.value, res.data);
  dialog.visible = true;
};
onMounted(() => {
  nextTick(() => {
    init(true);
  });
});
</script>

<style lang="scss" scoped>
.cwdt {
  width: 100%;
  height: 100%;
  font-family: 'DingTalk';
  .el-card {
    max-height: calc(90vh - 200px) !important;
    background: #178af01a;
    border: none;
    overflow: hidden auto;
    .el-pagination {
      margin-top: 10px;
      display: flex;
      justify-content: flex-end;
    }
  }
  .tableItem {
    display: flex;
    color: white;
    height: 120px;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(23, 138, 240, 0.2);
    cursor: pointer;
    .left {
      width: 160px;
      height: 100%;
      margin-right: 10px;
    }
    .right {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .top {
        .top-title {
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
        .title {
          font-size: 18px;
          line-height: 30px;
        }
        .sxlx {
          color: #409eff;
        }
      }
    }
  }
  .el-form--inline {
    .el-form-item {
      margin-right: 20px;
    }
    :deep(.el-input) {
      width: 120px;
      .el-input__inner {
        font-family: 'DingTalk';
      }
    }
  }
}
</style>
